/*  header-comment
/*  file   : /Users/arida/react-hrm-h5/src/utils/lwp
/*  author : arida
/*  date   : 2017-6-4 18:25:59
/*  last   : 2017-7-3 20:25:31
*/
import { merge } from "./common";
import wpo from '@ali/retcodelog';

// lwp ： light weight protocol
// 目前采用的是http， 如果需要转化为lwp， 记得引入这个文件
const lwp = (mergeUrl, opts) =>
  new Promise(function(resolve, reject) {
    window.dd.internal.request.lwp({
      uri: mergeUrl,
      body: opts.body,
      headers: merge(
        {
          referer: window.location.href
        },
        opts.headers
      ),
      onSuccess: function(res) {
        resolve(res);
      },
      onFail: function(error) {
        wpo.log("lwperror" + mergeUrl + JSON.stringify(error))
        reject(error);
      }
    });
  });
export default lwp;
